package com.whmskj.xjlhsc.stationmachine.service.imp;

import com.whmskj.xjlhsc.panel.pojo.vo.ProcessListVO;
import com.whmskj.xjlhsc.panel.pojo.vo.ProduceVO;
import com.whmskj.xjlhsc.panel.service.IProduceService;
import com.whmskj.xjlhsc.stationmachine.mapper.EmployeeInformationMapper;
import com.whmskj.xjlhsc.stationmachine.pojo.vo.EmployeeFines;
import com.whmskj.xjlhsc.stationmachine.pojo.vo.EmployeeInformationVO;
import com.whmskj.xjlhsc.stationmachine.pojo.vo.EmployeeRewards;
import com.whmskj.xjlhsc.stationmachine.pojo.vo.ProcessAttendanceVO;
import com.whmskj.xjlhsc.stationmachine.service.IEmployeeInformationControllerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author jiaruchun
 * @date 2025-09-18 15:01
 */
@Service
public class EmployeeInformationControllerServiceImpl implements IEmployeeInformationControllerService {
    @Autowired
    private EmployeeInformationMapper employeeInformationMapper;
    @Autowired
    private IProduceService produceService;

    @Override
    public EmployeeInformationVO getEmployeeInformation() {
        EmployeeInformationVO employeeInformationVO = new EmployeeInformationVO();
        List<ProcessAttendanceVO> processAttendanceList = employeeInformationMapper.getWeekData();
        if(processAttendanceList != null && processAttendanceList.size() > 0){
            employeeInformationVO.setThisWeekWorkers(processAttendanceList.get(0).getTotalOrAverage());
        }else {
            employeeInformationVO.setThisWeekWorkers(0F);
        }
        List<ProcessAttendanceVO> processAttendanceListShift = employeeInformationMapper.getShiftData();
        if(processAttendanceListShift != null && processAttendanceListShift.size() > 0){
            employeeInformationVO.setThisShiftSchedule(processAttendanceListShift.get(0).getTotalOrAverage());
        }else {
            //
            List<ProcessListVO> processList = produceService.getProcessList();
            processAttendanceListShift = processList.stream().map(processListVO -> new ProcessAttendanceVO(0F, processListVO.getProcess(), 0)).collect(Collectors.toList());
            employeeInformationVO.setThisShiftSchedule(0F);
        }
        List<ProcessAttendanceVO> monthData = employeeInformationMapper.getMonthData();
        if(monthData != null && monthData.size() > 0){
            employeeInformationVO.setThisMonthAverage(monthData.get(0).getTotalOrAverage());
        }else {
            employeeInformationVO.setThisMonthAverage(0F);
        }
        employeeInformationVO.setProcessAttendanceListWeek(processAttendanceList);
        employeeInformationVO.setProcessAttendanceListShift(processAttendanceListShift);
        employeeInformationVO.setProcessAttendanceListMonth(monthData);
        //奖惩--------------------------------------------
        List<EmployeeRewards> employeeRewardList = employeeInformationMapper.getEmployeeRewards();
        if(employeeRewardList != null && employeeRewardList.size() > 0){
            employeeInformationVO.setThisMonthReward(employeeRewardList.get(employeeRewardList.size() - 1).getRewardAmount());
        }else {
            employeeInformationVO.setThisMonthReward(0F);
        }
        List<EmployeeFines> employeeFines = employeeInformationMapper.getEmployeeFines();
        if(employeeFines != null && employeeFines.size() > 0){
            employeeInformationVO.setThisMonthFine(employeeFines.get(employeeFines.size() - 1).getFineAmount());
        }else {
            employeeInformationVO.setThisMonthFine(0F);
        }
        employeeInformationVO.setRewardsList(employeeRewardList);
        employeeInformationVO.setFinesList(employeeFines);
        return employeeInformationVO;
    }
}
